﻿using Cysharp.Threading.Tasks;
using System.Collections.Generic;
using UniRx;
using UnityEngine;

public class GameManager : USaSingletonBase<GameManager>
{
#if UNITY_EDITOR
    // 从start场景开始游戏
    [RuntimeInitializeOnLoadMethod]
    private static void Initialize()
    {
        var sceneNames = new List<string> { "Start", "Test" };
        if (sceneNames.Contains(SceneManager.currentScene.name)) return;
        SceneManager.LoadSceneAsync("Start", false).Forget();
    }
#endif

    protected async override void OnInit()
    {
        await GameConstructor.WaitForReady();
        LoadMainMenu();
    }

    public async void LoadMainMenu()
    {
        await SceneManager.LoadSceneAsync("Empty", false);
        UIManager.Find<MainMenuPanel>().Show();
    }

    public void NewGame()
    {
        SceneManager.LoadSceneAsync(GameData.instance.respawnSceneId);
    }

    public void LoadGame()
    {

    }

    public void QuitGame()
    {
#if UNITY_EDITOR
        UnityEditor.EditorApplication.isPlaying = false;
#else
        Application.Quit(); 
#endif
    }
}